/*
 * @Author: zhangyun
 * @Date: 2021-04-26 15:43:45
 * @LastEditors: zhangyun
 * @LastEditTime: 2021-04-26 16:06:51
 * @Desc:
 */
const jwt = require('jsonwebtoken')
const SECRET = 'ewgfvwergvwsgw5454gsrgvsvsd'

const auth = async (req, res) => {
  console.log(req.headers)
  const raw = String(req.headers.authorization).split(' ').pop()
  // 验证
  const { id } = jwt.verify(raw, SECRET)
  req.user = await User.findById(id)
}

module.exports = auth
